package com.kancy.drools.demo.timer;

import com.kancy.drools.demo.BaseTests;
import org.junit.Test;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;

/**
 * @author kancy
 * @date 2020/1/19 11:21
 **/
public class TimerTests extends BaseTests {
    @Test
    public void test() throws InterruptedException {
        KieContainer kieContainer = getKieContainer();
        KieSession kieSession = kieContainer.newKieSession("timer-session");
        // 异步触发规则执行
        ForkJoinPool.commonPool().execute(() -> kieSession.fireUntilHalt());
        // 30秒后终止规则执行
        TimeUnit.SECONDS.sleep(30);
        kieSession.halt();
        kieSession.dispose();
    }
}
